#ifndef FRAMELESSWINDOW_H
#define FRAMELESSWINDOW_H
#include <QQuickWindow>
#include <QQmlEngine>

class FramelessWindow:public QQuickWindow
{
    Q_OBJECT
    QML_ELEMENT


    Q_PROPERTY(MousePostition mouse_pos READ getMouse_pos WRITE setMouse_pos NOTIFY mouse_posChanged FINAL)

    Q_PROPERTY(bool resizeing READ getResizeing WRITE setResizeing NOTIFY resizeingChanged FINAL)


public:
    enum MousePostition{
        TOPLEFT = 1,TOP,TOPRIGHT,LEFT,RIGHT,BOTTOMLEFT,BOTTOM,BOTTOMRIGHT,NORMAL
    };
    Q_ENUM(MousePostition)

    FramelessWindow(QWindow *parent = nullptr);

    // QWindow interface
    MousePostition getMouse_pos() const;
    void setMouse_pos(MousePostition newMouse_pos);

    bool getResizeing() const;
    void setResizeing(bool newResizeing);

signals:
    void mouse_posChanged();

    void resizeingChanged();

protected:
    void mousePressEvent(QMouseEvent *) override;
    void mouseReleaseEvent(QMouseEvent *) override;
    void mouseMoveEvent(QMouseEvent *) override;
    void showEvent(QShowEvent *) override;

private:


    void setWindowGeometry(const QPointF&pos);

    void setCursorIcon();


    MousePostition getMousePos(QPointF &pos);

    //缩放边距
    int step = 4;
    //鼠标大概位置
    MousePostition mouse_pos = NORMAL;

    bool resizeing = false;

    Qt::CursorShape resizeCursor = Qt::ArrowCursor;
    //起始位置
    QPointF start_pos;
    //旧位置
    QPointF old_pos;
    //旧大小
    QSize old_size;



};

#endif // FRAMELESSWINDOW_H
